/* ************************************************************************* **
**                                                                           **
**                 Proprietary and Confidential Information                  **
**                                                                           **
**                Copyright (c) 2002 Oasis Semiconductor Inc.                **
**                                                                           **
**  This software contains proprietary and confidential material which is    **
**  property of Oasis Semiconductor Inc.                                     **
**                                                                           **
** ************************************************************************* */
#ifndef _MONMEM_H_
# define _MONMEM_H_
#include "ospl.h"

extern void printOut(const char* fmt, ...);

/******************************************************************************
*  FILE FORMAT:
*      1. ENUMERATIONS
*      2. DEFINES
*      3. STRUCTURES
*      4. ALLOCS
*      5. FUNCTIONS
******************************************************************************/
/******************************************************************************
*  1. ENUMERATIONS
******************************************************************************/
/******************************************************************************
*  2. DEFINES
******************************************************************************/
# if CHIPID_DC2 == OA_CHIPID
#  define MEM_DCREG_BASE 0xc0000000
# elif CHIPID_VEGAS >= OA_CHIPID
#  define MEM_DCREG_BASE 0xf0000000
# elif CHIPID_COBRA == OA_CHIPID
#  define MEM_DCREG_BASE 0xf0000000
# elif CHIPID_GILA == OA_CHIPID
#  define MEM_DCREG_BASE 0xf0000000
# elif CHIPID_IGUANA == OA_CHIPID
#  define MEM_DCREG_BASE 0xf0000000
# elif CHIPID_DINGO == OA_CHIPID
#  define MEM_DCREG_BASE 0xf0000000
# elif CHIPID_CHUCKWALLA == OA_CHIPID // NNIGROTBD
#  define MEM_DCREG_BASE 0xf0000000
# elif CHIPID_JACKAL == OA_CHIPID 
#  define MEM_DCREG_BASE 0xf0000000
# elif CHIPID_CARACAL == OA_CHIPID 
#  define MEM_DCREG_BASE 0xf0000000
# elif CHIPID_NASHOBA == OA_CHIPID 
#  define MEM_DCREG_BASE 0xf0000000
# elif CHIPID_NORTHSTAR == OA_CHIPID 
#  define MEM_DCREG_BASE 0xf0000000
# elif CHIPID_GREYLOCK == OA_CHIPID 
#  define MEM_DCREG_BASE 0xf0000000
# else
#  error Bad value for OA_CHIPID
# endif // CHIPID_DC2 == OA_CHIPID

/******************************************************************************
*  3. STRUCTURES
******************************************************************************/
/******************************************************************************
*  4. ALLOCS
******************************************************************************/
/******************************************************************************
*  5. FUNCTIONS
******************************************************************************/
CPP DBGMON_API UINT32 monARMRead(int a, int *d);
CPP DBGMON_API UINT32 monARMReadMultiple(int a, int n, int addrPolicy, UINT8 *d);
CPP DBGMON_API UINT32 monARMReadWord(int a, int *d);
CPP DBGMON_API UINT32 monARMReadDword(int a, int *d);
CPP DBGMON_API UINT32 monARMReadBurst(int a, int n, char *d);
CPP DBGMON_API UINT32 monMemReadChannel(int n, MEMIO *mio, UINT32 channel);
CPP DBGMON_API UINT32 monMemRead(int n, MEMIO *mio);
CPP DBGMON_API int ARMread(char *s, FILE *in, int argc, char **argv);
CPP DBGMON_API UINT32 monMemReadChannel(int n, MEMIO *mio, UINT32 channel);
CPP DBGMON_API int ARMpollread(char *s, FILE *in, int argc, char **argv);
CPP DBGMON_API int armread_m(char *s, FILE *in, int argc, char **argv);
CPP DBGMON_API int read_UINT16(FILE *fp, unsigned short *x);
CPP DBGMON_API int read_UINT32(FILE *fp, unsigned long *x);

/*
  Read len bytes from fixed processor address addr, width bytes at a time.
  0 < width <= 4.  In the case of width == 2, for example, each pair of
  bytes is read from addr and addr + 1.
*/
CPP DBGMON_API UINT32 monARMReadFixed(UINT32 addr, UINT32 len, int width, void *data);

CPP DBGMON_API UINT32 monMemWrite(int n, MEMIO *mio);
CPP DBGMON_API UINT32 monARMWrite(int a, int d);
CPP DBGMON_API UINT32 monARMWriteDword(int a, int d);
CPP DBGMON_API UINT32 monARMWriteBurst(int a, int n, void *d);
CPP DBGMON_API UINT32 monARMWriteBurstSkip(int a, int n, char *d);
CPP DBGMON_API int ARMwrite(char *s, FILE *in, int argc, char **argv);
CPP DBGMON_API int armwrite_m(char *s, FILE *in, int argc, char **argv);
CPP DBGMON_API int ARMdump(char *s, FILE *in, int argc, char **argv);
CPP DBGMON_API int ARMdump_f(FILE *fp, UINT32 a, UINT32 n);
CPP DBGMON_API int ARMload(char *s, FILE *in, int argc, char **argv);
CPP DBGMON_API int init_monmem(void);

/*
  Write len bytes to fixed processor address addr, width bytes at a time.
  0 < width <= 4.  In the case of width == 2, for example, each pair of
  bytes is written to addr and addr + 1.
*/
CPP DBGMON_API UINT32 monARMWriteFixed(UINT32 addr, UINT32 len, int width, void *d);


CPP DBGMON_API int dbgmonRammgrResolveSB(char *SBName,UINT8 instanceIndex,UINT32 *aAddress,UINT32 *aSize);

# ifndef SIMULATION
static __inline UINT32 regwr(int a, int d)
{
  UINT32 status;
  status=monARMWrite(a|MEM_DCREG_BASE,d);
  return(status);
}

static __inline UINT32 regwr16(int a, int d)
{
  UINT32 status;
  UINT32 data = d;
  status=monARMWriteBurst(a|MEM_DCREG_BASE,2,&data);
  return(status);
}

static __inline UINT32 regwr32(int a, int d)
{
  UINT32 status;
  UINT32 data = d;
  status=monARMWriteBurst(a|MEM_DCREG_BASE,4,&data);
  return(status);
}

static __inline UINT32 regrd(int a, int *d)
{
  UINT32 status;
  status=monARMRead(a|MEM_DCREG_BASE,d);
  return(status);
}

static __inline UINT32 regrd16(int a, int *d)
{
  UINT32 status;
  status=monARMReadBurst(a|MEM_DCREG_BASE,2,(char *) d);
  return(status);
}

static __inline UINT32 regrd32(int a, int *d)
{
  UINT32 status;
  status=monARMReadBurst(a|MEM_DCREG_BASE,4,(char *) d);
  return(status);
}
# endif //ndef SIMULATION

#endif  /* _MONMEM_H_ */
